import { Action } from "@/mdesign-lib/mdesign-app.umd.js";
import { archService } from "@/mdesign-lib/mdesign-app.umd.js";
import { Shape, GraphModel } from "@/mdesign-lib/mdesign-graph.umd.js";
import { GraphPopmenuItem } from "@/mdesign-lib/mdesign-app.umd.js";
import { ActionKey } from "@/mdesign-lib/mdesign-app.umd.js";

export class RealizeAllExchangeAction extends Action {
  keyName = "realizeAllExchange" as ActionKey;
  desc = "realizeAllExchange";

  async run(projectId: string, { modelId, stereotype }: { modelId: string; stereotype: string }) {
    await archService.realizeAllExchange(projectId, modelId, stereotype);
  }

  async onShapeMenuClick(graph: GraphModel, shape: Shape, menuItem: GraphPopmenuItem) {
    const modelId = shape.modelId;
    const projectId = app.activeProject!.id;
    await this.run(projectId, { modelId, stereotype: menuItem.modelId });
    graph.popMenuModel.freshMenuItems();
  }
}
